package com.citycloud.ccuap.tc.admin.clientresourceinterfacerel;

import static org.springframework.data.domain.Sort.Direction.DESC;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.domain.Sort;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.citycloud.ccuap.commons.constants.GlobalOperateType;
import com.citycloud.ccuap.commons.openapi.controller.base.BaseController;
import com.citycloud.ccuap.commons.web.session.SessionConstant;
import com.citycloud.ccuap.commons.web.session.CurrentUser;
import com.citycloud.ccuap.commons.web.util.ResolveRequest;
import com.citycloud.ccuap.commons.db.LikeMatchMode;
import com.citycloud.ccuap.commons.db.SqlRestrictions;
import com.citycloud.ccuap.framework.flexjson.JSONDeserializer;
import com.citycloud.ccuap.framework.flexjson.transformer.DateTransformer;
import com.citycloud.ccuap.commons.json.JSONData;
import com.citycloud.ccuap.commons.json.JSONUtil;
import com.citycloud.ccuap.commons.json.TreeNode;
import com.citycloud.ccuap.framework.mybatis.pagination.PageQuery;
import com.citycloud.ccuap.framework.util.ClassUtil;
import com.citycloud.ccuap.framework.util.DateUtil;
import com.citycloud.ccuap.framework.util.ExcelUtil;
import com.citycloud.ccuap.framework.util.StringUtil;
import com.citycloud.ccuap.tc.admin.entity.SysClientResourceInterfaceRel;

/**
 * @author zhangxu
 */
@Api("应用资源接口关联")
@RestController
@RequestMapping("/v1/admin/clientresourceinterfacerel")
public class ClientResourceInterfaceRelController extends BaseController {
	@Autowired
    private IClientResourceInterfaceRelService clientResourceInterfaceRelService;
    
	
	/**
	 * 默认构造函数
	 */
	public ClientResourceInterfaceRelController() {
	}

	@ApiOperation("保存对象")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public JSONData save(@RequestBody List<SysClientResourceInterfaceRel> sysClientResourceInterfaceRels) throws Exception {
		String resourceId = getStringParameter("resourceId");
		clientResourceInterfaceRelService.saveSysClientResourceInterfaceRels(sysClientResourceInterfaceRels,resourceId);

		JSONData jsonData = new JSONData("保存应用资源接口关联成功！");
		return jsonData;
	}


	/**
	 * 获取页面提交的对象
	 * 
	 * @return struts result
	 * @throws Exception
	 */
	private SysClientResourceInterfaceRel getRequestDataObject(short operateType) throws Exception {
		SysClientResourceInterfaceRel sysClientResourceInterfaceRel = new SysClientResourceInterfaceRel();
		ResolveRequest.fillData(request, sysClientResourceInterfaceRel);
		CurrentUser user = getCurrentUser();
		if (GlobalOperateType.ADD == operateType) {
		} else if (GlobalOperateType.EDIT == operateType) {
		}

		return sysClientResourceInterfaceRel;
	}
	
	@ApiOperation("新增对象")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JSONData add() throws Exception {
		SysClientResourceInterfaceRel sysClientResourceInterfaceRel = getRequestDataObject(GlobalOperateType.ADD);
		clientResourceInterfaceRelService.insert(sysClientResourceInterfaceRel);

		JSONData jsonData = new JSONData("添加应用资源接口关联成功！");
		return jsonData;
	}

	@ApiOperation("根据条件查询对象")
	@RequestMapping(value = "/query", method = { RequestMethod.GET, RequestMethod.POST })
	public JSONData query() throws Exception {
		PageQuery<SysClientResourceInterfaceRel> pageQuery = ResolveRequest.getPageForParams(request);
		SysClientResourceInterfaceRelDTO sysClientResourceInterfaceRelDTO = new SysClientResourceInterfaceRelDTO();
		ResolveRequest.fillData(request, sysClientResourceInterfaceRelDTO, "q_", true);
		
		Sort sort = Sort.by(DESC, "relId");
		pageQuery.setSort(sort);
		
		
		PageQuery<SysClientResourceInterfaceRel> pageData = clientResourceInterfaceRelService.selectPage(pageQuery, sysClientResourceInterfaceRelDTO);
		
		JSONData jsonData = new JSONData(pageData);
		return jsonData;
	}

	@ApiOperation("根据条件查询对象")
	@RequestMapping(value = "/queryall", method = { RequestMethod.GET, RequestMethod.POST })
	public JSONData queryall() throws Exception {
		String resourceId = getStringParameter("resourceId");
		List<Map<String, Object>> map = clientResourceInterfaceRelService.queryAll(resourceId);
		JSONData jsonData = new JSONData(map);
		return jsonData;
	}

}